package com.jcfk.eam.controller.main;

import cn.hutool.core.util.StrUtil;
import com.jcfk.common.business.log.annotation.RequestLogHeader;
import com.jcfk.common.web.domain.*;
import com.jcfk.eam.domain.dto.main.EamPointCheckDetailDTO;
import com.jcfk.eam.domain.query.main.EamPointCheckDetailQuery;
import com.jcfk.eam.service.main.EamPointCheckDetailService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
/**
 * 资产点检工单明细
 *
 * @author yrl
 * @email 
 * @date 2024-11-06
 */
@Api(tags = {"资产点检工单明细管理"})
@RestController
@RequestMapping("eampointcheckdetail")
public class EamPointCheckDetailController {
    @Autowired
    private EamPointCheckDetailService eamPointCheckDetailService;

    /**
     * 分页列表
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "ReqPageParam<EamPointCheckDetailQuery>", name = "requestParam", value = "", required = true)
    })
    @ApiOperation("分页查询资产点检工单明细")
    @PostMapping("/queryByPage")
    public RetPage<EamPointCheckDetailDTO> queryByPage(@RequestBody ReqPageParam<EamPointCheckDetailQuery> requestParam) {
        //设置默认排序
        if(requestParam.getSort().getOrderItem()==null){
            ReqSortParam<EamPointCheckDetailQuery> sortParam=new ReqSortParam();
            sortParam.setColumn("lastUpdateTime");
            sortParam.setOrderBy("desc");
            requestParam.setSort(sortParam);
        }
        DataPage<EamPointCheckDetailDTO> page = new DataPage<EamPointCheckDetailDTO>((long) requestParam.getCurrent(),
                (long) requestParam.getSize(),
                requestParam.getSort().getOrderItem(),
            EamPointCheckDetailDTO.class);
        page = eamPointCheckDetailService.queryByPage(page, requestParam.getData());

        return new RetPage<>(page);
    }


    /**
     *  资产点检工单明细
     * 根据id 查询详情
     */
    @ApiOperation("查询资产点检工单明细")
    @GetMapping("/get/{id}")
    public RetResult<EamPointCheckDetailDTO> get(@PathVariable("id") String id) {
            EamPointCheckDetailDTO item = eamPointCheckDetailService.get(id);
        return RetResult.ok(item);
    }

    /**
     * 添加/更新管理资产点检工单明细
     */
    @ApiOperation("保存资产点检工单明细")
    @PostMapping("/save")
    @RequestLogHeader(modular = "资产点检工单明细管理", businessType = "保存")
    public RetResult<?> save(@RequestBody @Valid EamPointCheckDetailDTO eamPointCheckDetail) {
        // 数据校验
        RetResult ret = eamPointCheckDetailService.isValid(eamPointCheckDetail);
        if (!ret.getCode().equals(RetResult.SUCCESS)) {
            return ret;
        }

        if (StrUtil.isEmpty(eamPointCheckDetail.getId())){
            // 新增
            eamPointCheckDetailService.insert(eamPointCheckDetail);
        } else{
            // 更新
            eamPointCheckDetailService.update(eamPointCheckDetail);
        }
        return RetResult.ok();

    }

    /**
     *  批量删除资产点检工单明细
     */
    @ApiOperation("批量删除资产点检工单明细")
    @PostMapping("/delete")
    @RequestLogHeader(modular = "资产点检工单明细管理", businessType = "批量删除")
    public RetResult<?> delete(@RequestBody EamPointCheckDetailDTO eamPointCheckDetail) {
        return RetResult.ok(eamPointCheckDetailService.removeBigBatch(eamPointCheckDetail.getIds()));
    }

    /**
     *  删除资产点检工单明细
     */
    @ApiOperation("删除资产点检工单明细")
    @PostMapping("/deleteItem/{id}")
    @RequestLogHeader(modular = "资产点检工单明细管理", businessType = "删除")
    public RetResult<?> deleteItem(@PathVariable("id") String id) {
        eamPointCheckDetailService.deleteItem(id);
        return RetResult.ok();
    }
}
